using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace FederationMembershipDB
{
	public class LineItem
	{
		private int _quantity;
		private double _price;
        private string _type; //type of item i.e. "membership", "product", "training pass"
        private object _item;

        public string Type 
        {
            get { return _type; }
            set { _type = value; }
        }

        public object Item
        {
            get { return _item; }
            set { _item = value; }
        }

        public int Quantity
        {
            get { return _quantity; }
            set { _quantity = value; }
        }

        public double Price
        {
            get { return _price; }
            set { _price = value; }
        }

		public void AddItem(int TransactionDetailsID, string sqlInsert)
		{
            //Parameter: ref int TrainingPassID - when trainingpass ID is set, the int variable passed in will be updated in the calling function

            //           SqlTransaction - to keep the transaction as a whole unit, pass in an existing Transaction

            int LineItemID = -1;

            //Get the last ID in the DB
            string sqlSelectID = "SELECT TOP(1) ID FROM LineItem Order By ID DESC;";
            DataSet ds = Utilities.SearchDatabase(sqlSelectID);

            //check to see if it will be the first item inserted.
            if (ds.Tables[0].Rows.Count == 0)
            {
                LineItemID = 0;
            }
            else
            {
                LineItemID = int.Parse(ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString()) + 1; // +1 to increment
            }
                       
            //Construct INSERT statement
            string strSQL;
            strSQL = string.Format(sqlInsert, LineItemID, Quantity, Price, TransactionDetailsID);

            Utilities.DatabaseNonQuery(strSQL);
		}
	}
}
